#include <graphics.h>
#include <conio.h>
#include <Windows.h>
COLORREF c1;
void main()
{
	initgraph(640, 480);
	int rectW = 640 / 16;
	int rectH = (460 - 40) / 8;
	int x, y;
	MOUSEMSG m,n;
	for (int i = 0; i<8; i++)
	{
		for (int j = 0; j<16; j++)
		{
			setfillcolor(WHITE);
			setcolor(BLACK);
			fillrectangle(j*rectW, i*rectH, rectW*(j + 1), rectH*(i + 1));
		}
	}
	for (int i=0;i<16;i++)
	{
		c1 = HSLtoRGB(i*(240 / 16), 1, 0.5);
		setfillcolor(c1);
		fillrectangle(i*rectW, 480 - 40, (i+1)*rectW, 480);
    }
		setfillcolor(WHITE);
	while (1)
	{
		if (MouseHit())
		{
			COLORREF c;
			m = GetMouseMsg();
			if (m.mkLButton)
			{
				x = m.x;
				y = m.y;
				if (y >= 480 - 40)
				{
					c = getpixel(x, y);
				    setfillcolor(c);
					fillcircle(x, y, 3);
				}
				else if (y <= 420)
				{
					int i = int(y / rectH);
					int j = int(x / rectW);
					if(i<8&&j<16)
					{ fillrectangle(j*rectW, i*rectH, rectW*(j + 1), rectH*(i + 1)); }
				}
			}
		}
	}
	_getch();
}